/* Copyright 2011 Elektrobit Wireless Communications Oy (EB)


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


 *All rights reserved 
 *Version:Elektrobit_Qt_1.0.0_20110305 */


#ifndef SERVICEMANAGER_H
#define SERVICEMANAGER_H

#include <services/services.h>
#include <QObject>
#include <QHash>

#define SERVICE_MANAGER ServiceManager::instance()
#define SERVICE(service_name) qobject_cast<service_name *>(SERVICE_MANAGER->getService(#service_name))


class ServiceManager : public QObject {
    Q_OBJECT
public:
    static ServiceManager *instance();
    Service *getService(const QString &serviceName);
    void init(const QString &configFile);
    void start();

signals:
    void servicesStarted();

private:
    ServiceManager(QObject *parent = 0);
    void startServices();
    int startService(Service *service);
    void loadServices();
    void loadBaseServices();
    void loadAppServices();
    
    Service *createServiceByType(const QString &type);
    
    QHash<QString, Service *> mServices;
    QList<Service *> mServicesList;
    QString mConfigFile;
    
    static ServiceManager *manager;
};

#endif // SERVICEMANAGER_H
